package com.lysj.merchant.merchant.controller;

import com.lysj.admin.utils.annotation.UserId;
import com.lysj.admin.utils.spring.foundation.base.BaseController;
import com.lysj.admin.utils.spring.foundation.pagination.PageVo;
import com.lysj.admin.utils.validation.annotation.Valid;
import com.lysj.admin.utils.web.Resp;
import com.lysj.merchant.merchant.domain.Store;
import com.lysj.merchant.merchant.service.StoreService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @author Created by wtl on 2019-03-12 17:25:12
 * @description 门店控制层
 */
@Slf4j
@RestController
@RequestMapping("/merchant/store")
public class StoreController extends BaseController<Store> {

    @Resource
    private StoreService storeService;

    @Override
    public StoreService getService() {
        return storeService;
    }

    /**
     * @author Created by wtl on 2019/3/19 14:40
     * @Description 商户添加门店
     */
    @PostMapping("/add")
    public Resp add(@UserId String userId,@Valid Store entity) {
        return new Resp().success(storeService.add(userId,entity));
    }

    /**
     * @author Created by wtl on 2019/3/13 18:48
     * @Description 根据登录id判断是商户还是店长获取门店
     */
    @GetMapping("/find_by_user_id")
    public Resp findById(@UserId String userId, PageVo pageVo) {
        return new Resp().success(storeService.findByStoreId(userId,pageVo));
    }

    /**
     * @author Created by wtl on 2019/3/18 16:47
     * @Description 根据登录用户获取门店下拉框
     */
    @GetMapping("/store_select")
    public Resp storeSelect(@UserId String userId) {
        return new Resp().success(storeService.storeSelect(userId));
    }

    /**
     * @author Created by wtl on 2019/3/19 11:31
     * @Description 获取登录用户的身份，商户还是店长
     */
    @GetMapping("/find_user_type")
    public Resp findUserType(@UserId String userId) {
        return new Resp().success(storeService.findUserType(userId));
    }

}
